# 定义函数 def 函数名称(形参)
from com.python复习.字典操作 import username


def mySort(alist):
    for i in range(0, len(alist) - 1):
        for j in range(0, len(alist) - i - 1):
            if alist[j] > alist[j + 1]:
                alist[j], alist[j + 1] = alist[j + 1], alist[j]
                # t = alist[j]
                # alist[j] = alist[j+1]
                # alist[j+1] = t
    return alist
# 函数调用
xlist = [2,32,1,24,52,55]
print(mySort(xlist))
# 缺省参数，默认参数
def login(password,username="admin"):
    if username == "admin" and password == "admin":
        return {"status":200,"msg":"登录成功"}
    else:
        return {"status": 400, "msg": "用户名或者密码错误"}
print(login("admin","admin"))
# 可变参数
def add(*args):
    sum = 0
    for a in args:
        sum += a
    return sum
result = add(1,2,3,4,5)
print(result)
# 函数练习作业
# 要求定义一个函数，定义一个字符串，计算子串出现的次数，并打印出来
def strcount(mainstr,childstr):
    print("子串出现的次数是%d"%mainstr.count(childstr))
strcount("adafasfdafjlkjkf","da")
# 定义一个函数，要求能够获取字符串中后10个字符，并打印出来
def strend10(string):
    result = string[len(string)-10::1]
    print("字符串%s的后10个字符是%s"%(string, result))
# 字典可变参数
def  login1(**kwargs):
    print(kwargs)
# 主函数
if __name__ == '__main__':
    login1(username="admin", password="123")
    strend10("adfdsf1234fda567890")